Ext.define('BenBen.common.FormWindow', {
	extend : 'Ext.window.Window',
	xtype : 'form-window',
    columnNum : 2,
	initComponent : function() {
        var panel = this;
        var config = this.config;
        var type = config.type;
        var method = 'POST';

        if(type != 1){
            method = 'PUT';
        }

        var title = '增加信息';
        var bbar = new Ext.Toolbar({
            items : [{
                xtype: 'tbfill'
            },{
                text : '确定',
                iconCls : 'formsave',
                handler : function() {
                    panel.dataForm.submit({
                        clientValidation:true,
                        waitMsg:'请稍候',
                        waitTitle:'正在验证',
                        url: config.url,
                        method:method,
                        success:function(form,action){
                            Ext.MessageBox.show({
                                width:150,
                                title:'成功',
                                buttons: Ext.MessageBox.OK,
                                msg:action.result.info
                            });
                            panel.hide();
                            config.store.load();
                        },
                        failure:function(form,action){
                            Ext.MessageBox.show({
                                width:150,
                                title:'失败',
                                buttons: Ext.MessageBox.OK,
                                msg:action.result.info
                            });
                        }

                    });
                }
            }, {
                text : '取消',
                iconCls : 'formcancle',
                handler : function() {
                    panel.hide();
                }
            },{
                xtype: 'tbfill'
            }]
        });

        if(type != 1){
            if(type == 2){
                title = '修改信息';
            }else{
                title = '查看信息';
                bbar = new Ext.Toolbar({
                    items : [{
                        xtype: 'tbfill'
                    },{
                        text : '取消',
                        iconCls : 'formcancle',
                        handler : function() {//点击触发的事件
                            panel.hide();
                        }
                    },{
                        xtype: 'tbfill'
                    }]
                });
            }
        }

		Ext.apply(this, {
			maximizable : true,
			modal : true,
			closeAction : 'hide',
			layout : 'anchor',
            title : title,
            border : false,
            bbar : bbar,
			items : [panel.dataForm]
		});
		this.callParent(arguments);
	}
});